$(function(){

	var user_id = "id";
	var get_coupon_url = "http://127.0.0.1/coupon/coupon/group/list";
	var coupon_id = "40288a6757d7105f0157d716aa540003";


	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]); return null;
	}


	function couponListCallback(data){
		if(data.status == "SUCCESS"){

			var html = "";

			for(var i = 0; i < data.content.content.length; i++){
				html += "<img src='"+ data.content.content[i].iconUrlNormal +"' />";
			}

			$(".coupon_list").append(html);
		}else if(data.status == "FAIL"){
			alert(data.message);
		}else{
			alert("获取优惠券列表异常！");
		}
	}


	var user_id_param = getQueryString(user_id);
		
	// 判断用户id是否获取成功
	if(user_id_param == null || user_id_param == ""){
		alert("获取用户ID失败！");
	}else{
		// 绑定优惠券
		$.ajax({
			type: "post",
			url: get_coupon_url,
			data: {
				params: JSON.stringify({
					id: coupon_id,
					userId: user_id
				})
			},
			success: couponListCallback
		});
	}
	
});